package cn.sylinx.horm.type.derby;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.sylinx.horm.type.JdbcType;
import cn.sylinx.horm.type.handler.BaseTypeHandler;

public class DerbyObjectTypeHandler extends BaseTypeHandler<Object> {

    @Override
    public void setParameter(PreparedStatement ps, int i, Object parameter) throws SQLException {

        if (parameter == null) {
            ps.setObject(i, null);
        } else {
            setNonNullParameter(ps, i, parameter);
        }
    }

    @Override
    protected JdbcType getJdbcTypeMapper() {
        return JdbcType.OTHER;
    }

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, Object parameter) throws SQLException {
        ps.setObject(i, parameter);
    }

    @Override
    public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
        return rs.getObject(columnName);
    }

    @Override
    public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        return rs.getObject(columnIndex);
    }

    @Override
    public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return cs.getObject(columnIndex);
    }

}
